package com.diorsunion.hedge.io;

import java.io.Serializable;

/**
 * Created by harley-dog on 2016/5/17.
 */
public class Message<T extends Serializable> implements Serializable {
    public final MessageType type;
    public final T data;
    private static final long serialVersionUID = 1123L;

    private Message(MessageType type, T data) {
        this.type = type;
        this.data = data;
    }

    public static final <T extends Serializable> Message<T> genMessage(MessageType type, T obj){
        return new Message<T>(type,obj);
    }

    public static final Message<Long> genHeartBeatMessage(){
        return new Message<Long>(MessageType.HeartBeat,System.currentTimeMillis());
    }


    @Override
    public String toString() {
        return "Message{" +
                "type=" + type +
                ", data=" + data +
                '}';
    }
}
